
#include <iostream>

#ifdef __cplusplus
extern "C" {
#endif
#include <libavutil/avutil.h>
#include <libavdevice/avdevice.h>
#include <libavcodec/avcodec.h>
#include <libavfilter/avfilter.h>
#include <libavformat/avformat.h>
#include <libswresample/swresample.h>
#include <libswscale/swscale.h>
#include <libavutil/log.h>
#include <SDL.h>
#ifdef __cplusplus
}
#endif
using namespace std;

int main(int argc, char** argv)
{
    av_log_set_level(AV_LOG_WARNING);
    AVFormatContext* inFmt = NULL;
    AVCodecContext* AudioCodec= NULL;
    AVCodecContext* VideoCodec= NULL;
   int res = avformat_open_input(&inFmt,"/home/todd/Videos/dde-introduction.mp4",NULL,NULL);
   if(res < 0)
   {
     av_log(NULL,AV_LOG_DEBUG,"%d","res = %d\n");
     return 0;
   }
   if((res = avformat_find_stream_info(inFmt,NULL)) < 0)
   {
        
     av_log(NULL,AV_LOG_DEBUG,"%d","res = %d\n");
     return 0;
   }
   int audio_index = -1;
   int videv_index = -1;
   for(int i = 0;i < inFmt->nb_streams; i++)
   {
        if(inFmt->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
        {
            audio_index = i;
        }
        else if(inFmt->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
        {
            videv_index = i;
        }
   }
    AVCodec* audio_codec = avcodec_find_decoder(inFmt->streams[audio_index]->codecpar->codec_id);
    if(!audio_codec)
    {
        av_log(NULL,AV_LOG_DEBUG,"audo codec null");
        return 0;
    }
    AVCodec* video_codec = avcodec_find_decoder(inFmt->streams[videv_index]->codecpar->codec_id);
    if(!video_codec)
    {
        av_log(NULL,AV_LOG_DEBUG,"video codec null");
        return 0;
    }
    AudioCodec = avcodec_alloc_context3(audio_codec);
    if(!AudioCodec)
    {
        av_log(NULL,AV_LOG_DEBUG,"audio codec context null");
    }
    VideoCodec = avcodec_alloc_context3(audio_codec);
    if(!VideoCodec)
    {
        av_log(NULL,AV_LOG_DEBUG,"video codec context null");
    }
    if((res = avcodec_open2(AudioCodec,audio_codec,NULL)) < 0)
    {
        av_log(NULL,AV_LOG_DEBUG,"avcodec_open2 error");
        return 0;
    }

 //   av_log(NULL,AV_LOG_WARNING,"OK");
    return 0;
}





